<template>
  <div class="p-30">
    <div>计算斐波那契数40</div>
    {{ d.name }}
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import FibWorker from '@/utils/worker/fib.js?worker'

const d = reactive({
  name: 'demo',
  time: '',
})
const worker = new FibWorker()
worker.postMessage(40)
worker.onmessage = (e) => {
  console.log(e.data)
  d.name = e.data
  if (e.data === 'ended') {
    worker.terminate() // 终止操作
  }
}
const init = () => {
  safeData(d, 'time', 1)
  d.time = formatTime(Date.now())
  return
}
init()
</script>

<style lang="scss"></style>
